home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / timeplt.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  7KB  |  241 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10.  
  11. extern unsigned char *spriteram,*spriteram_2;
  12. extern size_t spriteram_size;
  13.  
  14. unsigned char *timeplt_videoram,*timeplt_colorram;
  15. static struct tilemap *bg_tilemap;
  16. static int flipscreen;
  17. static int sprite_multiplex_hack;
  18.  
  19.  
  20. void init_timeplt(void)
  21. {
  22.     sprite_multiplex_hack = 1;
  23. }
  24.  
  25. void init_psurge(void)
  26. {
  27.     sprite_multiplex_hack = 0;
  28. }
  29.  
  30.  
  31. /***************************************************************************
  32.  
  33.   Convert the color PROMs into a more useable format.
  34.  
  35.   Time Pilot has two 32x8 palette PROMs and two 256x4 lookup table PROMs
  36.   (one for characters, one for sprites).
  37.   The palette PROMs are connected to the RGB output this way:
  38.  
  39.   bit 7 -- 390 ohm resistor  -- BLUE
  40.         -- 470 ohm resistor  -- BLUE
  41.         -- 560 ohm resistor  -- BLUE
  42.         -- 820 ohm resistor  -- BLUE
  43.         -- 1.2kohm resistor  -- BLUE
  44.         -- 390 ohm resistor  -- GREEN
  45.         -- 470 ohm resistor  -- GREEN
  46.   bit 0 -- 560 ohm resistor  -- GREEN
  47.  
  48.   bit 7 -- 820 ohm resistor  -- GREEN
  49.         -- 1.2kohm resistor  -- GREEN
  50.         -- 390 ohm resistor  -- RED
  51.         -- 470 ohm resistor  -- RED
  52.         -- 560 ohm resistor  -- RED
  53.         -- 820 ohm resistor  -- RED
  54.         -- 1.2kohm resistor  -- RED
  55.   bit 0 -- not connected
  56.  
  57. ***************************************************************************/
  58. void timeplt_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  59. {
  60.     int i;
  61.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  62.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  63.  
  64.  
  65.     for (i = 0;i < Machine->drv->total_colors;i++)
  66.     {
  67.         int bit0,bit1,bit2,bit3,bit4;
  68.  
  69.  
  70.         bit0 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  71.         bit1 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  72.         bit2 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  73.         bit3 = (color_prom[Machine->drv->total_colors] >> 4) & 0x01;
  74.         bit4 = (color_prom[Machine->drv->total_colors] >> 5) & 0x01;
  75.         *(palette++) = 0x19 * bit0 + 0x24 * bit1 + 0x35 * bit2 + 0x40 * bit3 + 0x4d * bit4;
  76.         bit0 = (color_prom[Machine->drv->total_colors] >> 6) & 0x01;
  77.         bit1 = (color_prom[Machine->drv->total_colors] >> 7) & 0x01;
  78.         bit2 = (color_prom[0] >> 0) & 0x01;
  79.         bit3 = (color_prom[0] >> 1) & 0x01;
  80.         bit4 = (color_prom[0] >> 2) & 0x01;
  81.         *(palette++) = 0x19 * bit0 + 0x24 * bit1 + 0x35 * bit2 + 0x40 * bit3 + 0x4d * bit4;
  82.         bit0 = (color_prom[0] >> 3) & 0x01;
  83.         bit1 = (color_prom[0] >> 4) & 0x01;
  84.         bit2 = (color_prom[0] >> 5) & 0x01;
  85.         bit3 = (color_prom[0] >> 6) & 0x01;
  86.         bit4 = (color_prom[0] >> 7) & 0x01;
  87.         *(palette++) = 0x19 * bit0 + 0x24 * bit1 + 0x35 * bit2 + 0x40 * bit3 + 0x4d * bit4;
  88.  
  89.         color_prom++;
  90.     }
  91.  
  92.     color_prom += Machine->drv->total_colors;
  93.     /* color_prom now points to the beginning of the lookup table */
  94.  
  95.  
  96.     /* sprites */
  97.     for (i = 0;i < TOTAL_COLORS(1);i++)
  98.         COLOR(1,i) = *(color_prom++) & 0x0f;
  99.  
  100.     /* characters */
  101.     for (i = 0;i < TOTAL_COLORS(0);i++)
  102.         COLOR(0,i) = (*(color_prom++) & 0x0f) + 0x10;
  103. }
  104.  
  105.  
  106.  
  107. /***************************************************************************
  108.  
  109.   Callbacks for the TileMap code
  110.  
  111. ***************************************************************************/
  112.  
  113. static void get_tile_info(int tile_index)
  114. {
  115.     unsigned char attr = timeplt_colorram[tile_index];
  116.     SET_TILE_INFO(0,timeplt_videoram[tile_index] + ((attr & 0x20) << 3),attr & 0x1f)
  117.     tile_info.flags = TILE_FLIPYX((attr & 0xc0) >> 6);
  118.     tile_info.priority = (attr & 0x10) >> 4;
  119. }
  120.  
  121.  
  122.  
  123. /***************************************************************************
  124.  
  125.   Start the video hardware emulation.
  126.  
  127. ***************************************************************************/
  128.  
  129. int timeplt_vh_start(void)
  130. {
  131.     bg_tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,TILEMAP_OPAQUE,8,8,32,32);
  132.  
  133.     if (!bg_tilemap)
  134.         return 1;
  135.  
  136.     return 0;
  137. }
  138.  
  139.  
  140.  
  141. /***************************************************************************
  142.  
  143.   Memory handlers
  144.  
  145. ***************************************************************************/
  146.  
  147. WRITE_HANDLER( timeplt_videoram_w )
  148. {
  149.     if (timeplt_videoram[offset] != data)
  150.     {
  151.         timeplt_videoram[offset] = data;
  152.         tilemap_mark_tile_dirty(bg_tilemap,offset);
  153.     }
  154. }
  155.  
  156. WRITE_HANDLER( timeplt_colorram_w )
  157. {
  158.     if (timeplt_colorram[offset] != data)
  159.     {
  160.         timeplt_colorram[offset] = data;
  161.         tilemap_mark_tile_dirty(bg_tilemap,offset);
  162.     }
  163. }
  164.  
  165. WRITE_HANDLER( timeplt_flipscreen_w )
  166. {
  167.     flipscreen = data & 1;
  168.     tilemap_set_flip(ALL_TILEMAPS,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
  169. }
  170.  
  171. /* Return the current video scan line */
  172. READ_HANDLER( timeplt_scanline_r )
  173. {
  174.     return cpu_scalebyfcount(256);
  175. }
  176.  
  177.  
  178.  
  179. /***************************************************************************
  180.  
  181.   Display refresh
  182.  
  183. ***************************************************************************/
  184.  
  185. static void draw_sprites(struct osd_bitmap *bitmap)
  186. {
  187.     const struct GfxElement *gfx = Machine->gfx[1];
  188.     const struct rectangle *clip = &Machine->drv->visible_area;
  189.     int offs;
  190.  
  191.  
  192.     for (offs = spriteram_size - 2;offs >= 0;offs -= 2)
  193.     {
  194.         int code,color,sx,sy,flipx,flipy;
  195.  
  196.         code = spriteram[offs + 1];
  197.         color = spriteram_2[offs] & 0x3f;
  198.         sx = 240 - spriteram[offs];
  199.         sy = spriteram_2[offs + 1]-1;
  200.         flipx = spriteram_2[offs] & 0x40;
  201.         flipy = !(spriteram_2[offs] & 0x80);
  202.  
  203.         drawgfx(bitmap,gfx,
  204.                 code,
  205.                 color,
  206.                 flipx,flipy,
  207.                 sx,sy,
  208.                 clip,TRANSPARENCY_PEN,0);
  209.  
  210.         if (sprite_multiplex_hack)
  211.         {
  212.             if (sy < 240)
  213.             {
  214.                 /* clouds are drawn twice, offset by 128 pixels horizontally and vertically */
  215.                 /* this is done by the program, multiplexing the sprites; we don't emulate */
  216.                 /* that, we just reproduce the behaviour. */
  217.                 if (offs <= 2*2 || offs >= 19*2)
  218.                 {
  219.                     drawgfx(bitmap,gfx,
  220.                             code,
  221.                             color,
  222.                             flipx,flipy,
  223.                             (sx + 128) & 0xff,(sy + 128) & 0xff,
  224.                             clip,TRANSPARENCY_PEN,0);
  225.                 }
  226.             }
  227.         }
  228.     }
  229. }
  230.  
  231. void timeplt_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  232. {
  233.     tilemap_update(ALL_TILEMAPS);
  234.  
  235.     tilemap_render(ALL_TILEMAPS);
  236.  
  237.     tilemap_draw(bitmap,bg_tilemap,0);
  238.     draw_sprites(bitmap);
  239.     tilemap_draw(bitmap,bg_tilemap,1);
  240. }
  241.